package com.garmin.tw.garminpcsync.android.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.garmin.tw.garminpcsync.android.R;

public class LazyAdapter extends BaseAdapter {
	
	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater=null;

	
	public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data=d;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return data.size();
	}
	
	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
		if (convertView==null) {
			vi = inflater.inflate(R.layout.list_item, null);
		}
		
		TextView title = (TextView)vi.findViewById(R.id.title); // title
		TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
		TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
		HashMap<String, String> song = data.get(position);

		// Setting all values in listview
		title.setText(song.get("lastestSku"));
		artist.setText(song.get("downloadUrl"));
		duration.setText(song.get("lastestVersion"));
		
		return vi;
	}
}
